﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using ERP.Manager.BusinessServices;

namespace ERP.Manager.Controllers.CustomAttributes
{
  
    public class CheckPersonnel:ActionFilterAttribute
    {

        public CheckPersonnel() { }



        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!HasData(filterContext))
            {

                ErrorRedirect(filterContext);
                return;
            }
        }


        private void ErrorRedirect(ActionExecutingContext filterContext)
        {
            filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary(new { controller = "Home", action = "CheckError" }));
        }
        private bool HasData(ControllerContext filterContext)
        {
            var userinfo = ContextService.Current;
            var result = userinfo.DepartmentId == "001" || userinfo.DepartmentId=="006";
            return result;
        }
    }
} 
